# 文件的读取
# 读取前两行内容
def read_file1():
    f=open("python.txt","r",encoding="utf-8")
    content=f.readline()
    print(f"第一行:{content}")

    content = f.readline()
    print(f"第二行:{content}")

    f.close()

# 读取全部内容
def read_file2():
    f=open("python.txt","r",encoding="utf-8")
    content=f.readlines()
    # 返回的是一个列表
    print(content)
    # ['窗前明月光\n', '疑是地上霜\n', '举头望明月\n', '低头思故乡']

    f.close()

def read_file3():
    for line in open("python.txt","r",encoding="utf8"):
        print(line)

def read_file4():
    with open("python.txt","r",encoding="utf8") as f:
        lines=f.readlines()
        for line in lines:
            # 通过strip方法，去除空格和换行符
            print(f"s-{line.strip()}-e")
        # 操作完成后自动关闭，执行close方法

read_file4()